const db = uniCloud.database();
const { curTimeStamp } = require('../../common/time');
module.exports = async function(options = {}) {
	const { clientIP, os, deviceId } = this.getClientInfo();
	const { characterId, item } = options;
	if (!characterId || !item) {
		throw new Error('缺少角色id或item参数');
	}
	const { total } = await db.collection('a-dz-active-list').where({ characterId }).count();
	if (total) {
		await db.collection('a-dz-active-list').where({ characterId }).update({
			dzItem: item,
			createTime: curTimeStamp()
		});
	} else {
		await db.collection('a-dz-active-list').add({
			dzItem: item,
			characterId,
			createTime: curTimeStamp()
		});
	}
	return {
		code: 0
	}
}